package com.sheng.sign.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.sign.entity.Classes;
import com.sheng.sign.service.ClassesService;

public class ClassesAction extends ActionSupport implements ModelDriven<Classes>{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3955503311378394481L;
	protected String forwardView;
	protected static final String ADD_JSP = "/page/Classes_add.jsp";
	protected static final String EDIT_JSP = "/page/Classes_edit.jsp";
	protected static final String LIST_JSP = "/page/Classes_list.jsp";
	
	private List<Classes> list;
	private Classes classes = new Classes();
	private ClassesService classesService;
	@Override
	public Classes getModel() {
		return classes;
	}
	
	public String openAdd() {
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	public String openEdit(){
		classes = classesService.findById(classes);
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月8日 下午4:14:29
	 */
	public String add() {
		classes.setIsDelete(0);
		boolean value = classesService.add(classes);
		if(value){
			setForwardView(LIST_JSP);
			return this.list();
		}else{
			return ERROR;
		}
	}
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月8日 下午4:14:13
	 */
	public String edit() {
		boolean value = classesService.edit(classes);
		if(value){
			return this.list();
		}else{
			return ERROR;
		}
	}
	
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月8日 下午4:14:10
	 */
	public String delete() {
		classes = classesService.findById(classes);
		boolean value = classesService.delete(classes);
		if(value){
			return this.list();
		}else{
			return ERROR;
		}
	}
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月8日 下午4:14:04
	 */
	public String list() {
		list = classesService.findAllList();
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String findByClassesName() {
		list = classesService.findByClassesName(classes);
		setForwardView(LIST_JSP);//选择后的班级学生信息页面，就开始进行签到操作
		return SUCCESS;
	}
	
	
	public List<Classes> getList() {
		return list;
	}

	public void setList(List<Classes> list) {
		this.list = list;
	}

	public Classes getClasses() {
		return classes;
	}

	public void setClasses(Classes classes) {
		this.classes = classes;
	}

	public ClassesService getClassesService() {
		return classesService;
	}

	public void setClassesService(ClassesService classesService) {
		this.classesService = classesService;
	}

	public String getForwardView() {
		return forwardView;
	}

	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}
	

}
